//
//  AutiVideoViewController.m
//  UniversalApp
//
//  Created by 志刚杨 on 2018/3/2.
//  Copyright © 2018年 voidcat. All rights reserved.
//

#import "AuthVideoViewController.h"
#import "AuthReadMeView.h"
#import "UploadAuthVideoViewController.h"
@interface AuthVideoViewController ()
{
    AuthReadMeView *_bottomView;
}
@end

@implementation AuthVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    [self setLayout];
}

-(void)createUI
{
    _bottomView = [AuthReadMeView getView];
    [self.view addSubview:_bottomView];
    [self.view bringSubviewToFront:_btnStartRecord];
    [self.view bringSubviewToFront:_btnDone];
    _progressView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 2);
    [self setLayout];
}

-(void)setLayout
{
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self.view).multipliedBy(2/5.0f);
        make.width.equalTo(self.view);
        make.bottom.and.left.equalTo(self.view);
    }];

    [_progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(2.0));
        make.width.equalTo(self.view);
        make.top.equalTo(_bottomView).offset(-2);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void) onRecordComplete:(TXUGCRecordResult*)result;
{   
    if (_appForeground)
    {
        if (result.retCode == UGC_RECORD_RESULT_OK) {
            [[HUDHelper sharedInstance] tipMessage:ASLocalizedString(@"录制成功")];
            UploadAuthVideoViewController *vc = [[UploadAuthVideoViewController alloc] init];
            [vc setVideoPath:result.videoPath];
            [self stopCameraPreview];
            [self.navigationController pushViewController:vc animated:NO];

        }
        else if(result.retCode == UGC_RECORD_RESULT_OK_BEYOND_MAXDURATION){
            [[HUDHelper sharedInstance] tipMessage:ASLocalizedString(@"时长过长，自动结束")];
            UploadAuthVideoViewController *vc = [[UploadAuthVideoViewController alloc] init];
            [vc setVideoPath:result.videoPath];
            [self.navigationController pushViewController:vc animated:NO];

            [self stopCameraPreview];
            [self resetVideoUI];
        }
        else if(result.retCode == UGC_RECORD_RESULT_OK_INTERRUPT){
            [[HUDHelper sharedInstance] tipMessage:ASLocalizedString(@"录制被打断")];
            //            [self toastTip:ASLocalizedString(@"录制被打断")];
        }
        else if(result.retCode == UGC_RECORD_RESULT_OK_UNREACH_MINDURATION){
            [[HUDHelper sharedInstance] tipMessage:ASLocalizedString(@"至少要录够5秒")];

            //            [self toastTip:ASLocalizedString(@"至少要录够5秒")];
        }
    }
    [self refreshRecordTime:0];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
